package com.imc.core.config.redis;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Slf4j
@Component
public class RedisScheduled {
    @Autowired
    RedisTimeClean[] redisTimeClean;

    @Value("${druid.redisTimeClean}")
    private String timeCleanState;

    @Scheduled(cron = "0 0 0,12 * * ?")
    public void doClean(){
        log.info(new Date().getTime()+",定时任务的开关状态:"+timeCleanState);
        if(timeCleanState.equals("close")){
            return;
        }
        for (RedisTimeClean redisTimeClean1 : redisTimeClean){
            try {
                redisTimeClean1.timeClean();
            }catch (Exception e){
                log.error("定时任务异常:"+e.getMessage());
            }
        }
    }
}
